package com.john.blog.controller.front;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.john.blog.common.constant.KeyConst;
import com.john.blog.controller.front.support.FrontBlogControllerSupport;

/**
 * 前端页面跳转
 * 
 * @author JiangGengchao
 * @date 2018年2月5日
 */
@Controller
public class FrontPageController extends FrontBlogControllerSupport {

    @Value("${remote.server}")
    private String REMOTE_SERVER;
    private final static String FRONT_LOCATION = "front/";

    @RequestMapping({ "/", "" })
    public String gotoIndex() {
        return "redirect:/blog/index";
    }

    @RequestMapping("/index")
    public String index() {
        return appendPackage("index");
    }

    @RequestMapping("/about")
    public String about() {
        return appendPackage("about");
    }

    @RequestMapping("/works")
    public String works() {
        return appendPackage("works");
    }

    @RequestMapping("/message")
    public String message() {
        return appendPackage("message");
    }

    @RequestMapping("/donate")
    public String donate() {
        return appendPackage("donate");
    }

    @RequestMapping("/query")
    public String query() {
        return appendPackage("query");
    }

    @RequestMapping("/query/category")
    public String category() {
        return appendPackage("category");
    }

    @RequestMapping("/query/tag")
    public String tag() {
        return appendPackage("tag");
    }

    @RequestMapping("/page/{ftlName}")
    public String blogPage(@PathVariable(value = "ftlName") String ftlName) {
        return "redirect:" + REMOTE_SERVER + KeyConst.TEMPLATE_PATH + "/" + ftlName + ".html";
    }

    /**
     * 添加包路径
     * 
     * @param page
     * @return
     */
    private String appendPackage(String page) {
        return FRONT_LOCATION + page;
    }

}
